<?
require_once('common.inc.php');
require_once(_INC_PATH.'database.php');
require_once(_INC_PATH.'page.inc.php');

if(!checkIsLogin())header("Location: /login.php");
$smarty->assign("myActive",'cor');
$cmd = @$_REQUEST['cmd'];
if($cmd == "ajaxSetTop"){
	ajaxSetTop();
}else{
	showMyPageList();
}

function showMyPageList()
{
	global $smarty;
	$db = new database();
	$user_id = _getcookie("id");
	$sql_count = "select count(*) from tbl_corporation where create_author='$user_id' and del_flg='0'";
	$total = $db->loadResult($sql_count);
	$curPage = @intval($arr_data['p']);
	if($curPage < 1) $curPage = 1;
	$showNum = _FORVIEWNUM;
	$pageLink = "/mycorporation.php";
	$page = new PageClass($total,$curPage,$showNum,$pageLink);
	$limitStart = $page->limitStart;
	$smarty->assign("pageList",$page->pageList);
	
	$sql = "select tc.*,ts.estimate_total from tbl_corporation tc left join tbl_statistic ts on ts.cor_id=tc.id where tc.create_author='$user_id' and tc.del_flg='0' order by tc.update_time desc limit $limitStart,$showNum";
	$db->setQuery($sql);
	$data = $db->loadAssocList();
	if(!empty($data))
	{
		foreach($data as $key=>$value){
			$data[$key]['bgcolor'] = $key%2==0?"est_2":"est_1";
			$data[$key]['create_time'] = substr($value['create_time'],0,10);;
		}
	}
	$smarty->assign("rows",$data);
	Display('mycorporation.tpl');
}
?>